<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">

// Ejemplo de como calcular una Tranformacion de View
// El punto de vista gira alrededor del centro de la palmera


var aspect = 1;
var escala = 50;

var d = 12;
var OX = 500;
var OY = 350;
var ep = 0.01;

// Matriz de View (Pasa de World Space a Camera Space)
var m11 = 1;		var m12 = 0;		var m13 = 0;
var m21 = 0;		var m22 = 1;		var m23 = 0;
var m31 = 0.141;	var m32 = 0.141;	var m33 = 0.707;
var tras_x = 0;		var tras_y = 0;		var tras_z = 0;

var canvas;
var ctx;

function Transform_X(x,y,z)
{
	// Paso de World Space a Camera Space 
	var xc = x*m11 + y*m21 + z*m31 + tras_x;
	var yc = x*m12 + y*m22 + z*m32 + tras_y;
	var zc = x*m13 + y*m23 + z*m33 + tras_z;
	// Perspectiva: Proyecto a Screen Space
	var xs = xc/(zc + d ) * d *escala;
	return xs;
}

function Transform_Y(x,y,z)
{
	// Paso de World Space a Camera Space 
	var xc = x*m11 + y*m21 + z*m31 + tras_x;
	var yc = x*m12 + y*m22 + z*m32 + tras_y;
	var zc = x*m13 + y*m23 + z*m33 + tras_z;
	// Perspectiva: Proyecto a Screen Space
	var ys = yc/(zc + d ) * d *escala * aspect;
	return ys;
}


// Proyecta y Dibuja un triangulo
function DrawTri(x0,y0,z0,x1,y1,z1,x2,y2,z2)
{

	ctx.beginPath();

	// Primer punto
	var X = Transform_X(x0,y0,z0);
	var Y = Transform_Y(x0,y0,z0);
	ctx.moveTo(OX + X, OY - Y);

	// Segundo punto
	X = Transform_X(x1,y1,z1);
	Y = Transform_Y(x1,y1,z1);
	ctx.lineTo(OX + X, OY - Y);

	// Tercer punto
	X = Transform_X(x2,y2,z2);
	Y = Transform_Y(x2,y2,z2);
	ctx.lineTo(OX + X, OY - Y);


	ctx.closePath();
	ctx.fill();
	ctx.stroke();
}


// Dibuja una linea
function Line3d(x0,y0,z0,x1,y1,z1)
{

	ctx.beginPath();

	// Primer punto
	var X = Transform_X(x0,y0,z0);
	var Y = Transform_Y(x0,y0,z0);
	ctx.moveTo(OX + X, OY - Y);

	// Segundo punto
	X = Transform_X(x1,y1,z1);
	Y = Transform_Y(x1,y1,z1);
	ctx.lineTo(OX + X, OY - Y);
	ctx.closePath();
	ctx.stroke();

}


// Dibuja una Palmera
function palmera() 
{
	ctx.fillStyle = 'rgba(120,255,120,0.4)';
	var coordinates = [0, 1, 2, 0, 2, 3, 3, 4, 5, 3, 5, 0, 4, 6, 7, 4, 7, 5, 4, 8, 6, 4, 9, 8, 3, 9, 4, 10, 11, 9, 11, 12, 9, 9, 3, 2, 9, 2, 10, 0, 13, 1, 5, 14, 13, 5, 13, 0, 14, 5, 15, 16, 17, 9, 9, 12, 16, 12, 18, 16, 11, 10, 19, 11, 19, 12, 10, 20, 19, 20, 21, 19, 22, 23, 12, 22, 12, 19, 24, 25, 23, 25, 26, 27, 25, 27, 23, 23, 22, 24, 28, 29, 30, 31, 1, 32, 31, 32, 33, 13, 34, 35, 13, 35, 36, 13, 36, 37, 34, 38, 39, 34, 39, 35, 37, 1, 13, 37, 40, 1, 40, 32, 1, 33, 29, 31, 29, 28, 31, 41, 2, 1, 41, 1, 31, 31, 28, 42, 31, 42, 41, 28, 43, 42, 28, 44, 43, 30, 44, 28, 30, 45, 44, 29, 45, 30, 29, 46, 45, 32, 47, 48, 32, 48, 33, 33, 48, 29, 48, 46, 29, 49, 42, 50, 49, 41, 42, 51, 52, 10, 51, 10, 2, 52, 53, 10, 2, 54, 51, 2, 41, 54, 41, 49, 54, 42, 55, 50, 42, 43, 55, 50, 56, 49, 50, 57, 56, 55, 57, 50, 49, 58, 54, 52, 59, 53, 52, 60, 59, 51, 60, 52, 51, 61, 60, 54, 61, 51, 62, 63, 64, 62, 65, 66, 62, 66, 63, 65, 20, 67, 65, 67, 66, 10, 53, 68, 68, 67, 10, 67, 20, 10, 69, 70, 65, 65, 62, 69, 62, 71, 69, 64, 72, 62, 64, 73, 72, 63, 73, 64, 63, 74, 73, 67, 75, 66, 67, 76, 75, 68, 76, 67, 68, 77, 76, 20, 65, 78, 20, 78, 21, 66, 74, 63, 36, 79, 37, 36, 80, 79, 38, 34, 81, 38, 81, 82, 81, 34, 83, 81, 83, 84, 81, 84, 85, 13, 14, 34, 14, 15, 83, 14, 83, 34, 15, 84, 83, 40, 47, 32, 40, 86, 47, 37, 86, 40, 37, 79, 86, 53, 77, 68, 53, 59, 77, 87, 7, 88, 87, 88, 89, 7, 6, 88, 7, 90, 5, 87, 91, 7, 87, 92, 91, 92, 87, 93, 92, 93, 94, 95, 93, 87, 87, 89, 95, 88, 6, 89, 96, 9, 97, 96, 98, 8, 96, 8, 9, 97, 99, 98, 98, 96, 97, 17, 100, 99, 17, 99, 97, 100, 17, 16, 100, 16, 93, 21, 101, 22, 21, 22, 19, 21, 78, 102, 21, 102, 101, 70, 78, 65, 103, 38, 104, 103, 39, 38, 103, 105, 39, 104, 106, 103, 104, 107, 106, 38, 108, 104, 38, 82, 108, 43, 109, 55, 44, 109, 43, 44, 45, 109, 108, 82, 110, 108, 107, 104, 72, 111, 62, 72, 73, 111, 35, 80, 36, 35, 112, 80, 39, 112, 35, 39, 105, 112, 113, 114, 115, 113, 116, 117, 113, 117, 15, 113, 15, 5, 116, 113, 115, 5, 118, 113, 5, 90, 118, 6, 95, 89, 95, 6, 8, 95, 8, 100, 91, 90, 7, 90, 91, 119, 90, 119, 120, 95, 100, 93, 100, 98, 99, 8, 98, 100, 9, 17, 97, 121, 94, 93, 93, 16, 121, 16, 122, 121, 122, 123, 121, 122, 16, 18, 122, 18, 124, 125, 126, 70, 70, 69, 125, 69, 71, 125, 56, 58, 49, 75, 74, 66, 111, 71, 62, 73, 127, 111, 73, 128, 109, 73, 129, 128, 109, 127, 73, 109, 57, 55, 45, 130, 109, 45, 131, 132, 48, 47, 131, 47, 86, 131, 86, 79, 131, 79, 80, 133, 79, 133, 131, 80, 112, 133, 112, 105, 132, 112, 132, 133, 131, 45, 46, 131, 46, 48, 106, 132, 103, 106, 130, 132, 106, 134, 130, 132, 130, 45, 132, 131, 133, 132, 105, 103, 130, 127, 109, 130, 135, 127, 130, 136, 137, 127, 71, 111, 127, 138, 71, 127, 139, 138, 127, 140, 141, 127, 135, 140, 128, 129, 60, 128, 60, 61, 129, 75, 76, 129, 76, 77, 129, 77, 59, 129, 59, 60, 75, 129, 73, 75, 73, 74, 61, 58, 128, 58, 56, 128, 56, 57, 109, 56, 109, 128, 58, 61, 54, 24, 22, 101, 24, 101, 142, 117, 143, 84, 117, 84, 15, 91, 92, 144, 91, 144, 145, 94, 121, 123, 94, 123, 144, 123, 146, 147, 147, 148, 144, 147, 144, 123, 144, 92, 94, 144, 148, 149, 144, 149, 145, 23, 150, 151, 23, 151, 12, 23, 152, 150, 120, 153, 154, 120, 154, 118, 120, 119, 153, 118, 90, 120, 118, 114, 113, 118, 155, 114, 154, 156, 155, 154, 155, 118, 153, 157, 154, 158, 159, 160, 158, 160, 161, 162, 18, 163, 161, 162, 163, 163, 158, 161, 161, 18, 162, 161, 124, 18, 161, 164, 124, 163, 150, 158, 163, 18, 151, 145, 157, 119, 145, 119, 91, 145, 165, 157, 122, 166, 146, 122, 146, 123, 151, 150, 163, 151, 18, 12, 150, 159, 158, 150, 152, 159, 124, 164, 122, 164, 166, 122, 119, 157, 153, 157, 156, 154, 157, 165, 156, 101, 102, 142, 102, 167, 142, 142, 168, 24, 168, 25, 24, 142, 167, 169, 142, 169, 168, 170, 143, 117, 117, 116, 170, 115, 171, 172, 171, 173, 172, 116, 115, 172, 116, 172, 170, 114, 174, 171, 114, 171, 115, 27, 152, 23, 27, 164, 152, 175, 176, 177, 176, 175, 178, 176, 178, 179, 177, 27, 175, 27, 180, 166, 26, 181, 182, 26, 182, 178, 26, 178, 175, 26, 175, 27, 25, 168, 181, 25, 181, 26, 183, 149, 148, 148, 147, 183, 146, 166, 183, 146, 183, 147, 155, 184, 114, 155, 165, 149, 156, 165, 155, 160, 164, 161, 159, 164, 160, 183, 185, 149, 183, 186, 185, 183, 187, 186, 149, 184, 155, 149, 165, 145, 149, 185, 184, 166, 164, 27, 166, 187, 183, 180, 188, 187, 187, 166, 180, 184, 189, 177, 184, 177, 114, 184, 185, 190, 152, 164, 159, 181, 168, 169, 181, 169, 191, 192, 193, 110, 192, 110, 85, 193, 107, 110, 193, 134, 107, 193, 194, 134, 192, 195, 196, 192, 196, 193, 85, 84, 192, 84, 143, 192, 82, 81, 85, 85, 110, 82, 110, 107, 108, 143, 170, 195, 143, 195, 192, 107, 134, 106, 134, 197, 130, 134, 194, 197, 195, 198, 199, 195, 199, 196, 198, 173, 200, 198, 200, 199, 195, 170, 198, 170, 172, 198, 196, 194, 193, 199, 201, 196, 198, 172, 173, 200, 201, 199, 200, 202, 201, 200, 203, 202, 200, 204, 203, 201, 194, 196, 197, 194, 202, 197, 136, 130, 202, 194, 201, 202, 203, 197, 70, 126, 102, 70, 102, 78, 126, 125, 205, 126, 205, 206, 125, 138, 205, 206, 167, 102, 206, 102, 126, 206, 207, 169, 206, 169, 167, 205, 208, 207, 205, 207, 206, 71, 138, 125, 138, 208, 205, 138, 139, 208, 209, 207, 208, 208, 210, 209, 209, 191, 169, 209, 169, 207, 209, 211, 191, 209, 210, 212, 209, 212, 211, 210, 139, 212, 208, 139, 210, 191, 211, 182, 191, 182, 181, 211, 212, 213, 211, 213, 214, 211, 214, 215, 211, 215, 182, 215, 216, 182, 216, 217, 178, 216, 178, 182, 218, 212, 141, 218, 219, 212, 218, 140, 219, 141, 139, 127, 141, 140, 218, 212, 139, 141, 176, 174, 114, 176, 114, 177, 174, 176, 179, 177, 220, 221, 221, 27, 177, 222, 223, 224, 222, 137, 223, 224, 225, 222, 224, 226, 225, 223, 227, 228, 229, 230, 231, 229, 232, 230, 228, 232, 229, 233, 234, 235, 233, 235, 236, 178, 217, 237, 238, 179, 178, 238, 178, 237, 234, 233, 179, 234, 179, 238, 235, 239, 236, 236, 239, 240, 236, 226, 224, 240, 226, 236, 240, 135, 226, 240, 241, 135, 239, 241, 240, 239, 242, 241, 235, 242, 239, 237, 243, 238, 238, 244, 234, 234, 245, 235, 234, 244, 245, 219, 213, 212, 219, 140, 213, 213, 246, 214, 216, 247, 217, 215, 248, 216, 215, 249, 248, 214, 249, 215, 250, 251, 252, 253, 254, 250, 231, 255, 253, 217, 256, 237, 217, 247, 256, 190, 257, 189, 190, 189, 184, 190, 186, 257, 257, 186, 189, 189, 220, 177, 188, 180, 258, 188, 259, 220, 188, 220, 187, 260, 221, 220, 258, 260, 259, 258, 259, 188, 258, 221, 260, 258, 180, 221, 203, 136, 197, 203, 261, 136, 225, 137, 222, 225, 135, 137, 226, 135, 225, 252, 262, 204, 204, 261, 203, 204, 262, 261, 185, 186, 190, 186, 187, 220, 186, 220, 189, 220, 259, 260, 221, 180, 27, 140, 246, 213, 137, 135, 130, 137, 227, 223, 135, 263, 140, 136, 264, 137, 263, 265, 140, 265, 263, 243, 265, 243, 256, 265, 256, 247, 263, 135, 245, 263, 245, 244, 263, 244, 243, 135, 241, 242, 135, 242, 245, 247, 248, 265, 140, 265, 248, 140, 248, 249, 140, 249, 246, 266, 264, 136, 264, 266, 254, 264, 254, 255, 264, 255, 230, 264, 230, 232, 266, 136, 262, 266, 262, 251, 266, 251, 254, 136, 261, 262, 137, 264, 232, 137, 232, 227, 227, 232, 228, 230, 255, 231, 245, 242, 235, 246, 249, 214, 248, 247, 216, 256, 243, 237, 255, 254, 253, 254, 251, 250, 243, 244, 238, 251, 262, 252, 267, 268, 269, 267, 269, 270, 267, 270, 271, 267, 271, 272, 268, 267, 273, 268, 273, 274, 268, 275, 276, 268, 276, 269, 276, 277, 278, 276, 278, 269, 278, 279, 269, 280, 270, 281, 280, 281, 282, 271, 270, 280, 283, 284, 273, 273, 267, 283, 285, 283, 267, 267, 272, 285, 286, 285, 272, 272, 271, 286, 287, 286, 271, 271, 280, 287, 288, 287, 280, 280, 282, 288, 289, 288, 282, 282, 281, 289, 290, 289, 281, 281, 270, 290, 291, 290, 270, 270, 269, 291, 292, 291, 269, 269, 279, 292, 293, 292, 279, 279, 278, 293, 294, 293, 278, 278, 277, 294, 295, 294, 277, 277, 276, 295, 296, 295, 276, 276, 275, 296, 297, 296, 275, 275, 268, 297, 298, 297, 268, 268, 274, 298, 284, 298, 274, 274, 273, 284, 286, 287, 290, 287, 288, 289, 287, 289, 290, 291, 292, 293, 295, 291, 293, 295, 293, 294, 295, 296, 297, 297, 291, 295, 297, 298, 284, 297, 284, 283, 283, 285, 286, 283, 286, 290, 283, 290, 291, 283, 291, 297, 299, 300, 301, 302, 299, 301, 303, 302, 301, 301, 304, 303, 305, 303, 304, 304, 306, 305, 307, 305, 306, 306, 308, 307, 309, 307, 308, 308, 310, 309, 311, 309, 310, 310, 312, 311, 313, 311, 312, 312, 314, 313, 315, 313, 314, 314, 316, 315, 317, 315, 316, 316, 318, 317, 319, 317, 318, 318, 320, 319, 321, 319, 320, 320, 322, 321, 323, 321, 322, 322, 324, 323, 325, 323, 324, 324, 326, 325, 327, 325, 326, 326, 328, 327, 329, 327, 328, 328, 300, 329, 303, 305, 311, 305, 307, 309, 305, 309, 311, 313, 315, 317, 321, 313, 317, 321, 317, 319, 321, 323, 325, 325, 313, 321, 325, 327, 329, 325, 329, 299, 299, 302, 303, 299, 303, 311, 299, 311, 313, 299, 313, 325, 330, 331, 332, 330, 332, 333, 330, 334, 335, 330, 336, 337, 330, 337, 331, 334, 330, 338, 334, 339, 340, 334, 340, 341, 341, 342, 335, 341, 335, 334, 343, 335, 344, 343, 344, 345, 336, 330, 335, 336, 335, 343, 346, 347, 332, 332, 331, 346, 348, 346, 331, 331, 337, 348, 349, 348, 337, 337, 336, 349, 350, 349, 336, 336, 343, 350, 351, 350, 343, 343, 345, 351, 352, 351, 345, 345, 344, 352, 353, 352, 344, 344, 335, 353, 354, 353, 335, 335, 342, 354, 355, 354, 342, 342, 341, 355, 356, 355, 341, 341, 340, 356, 357, 356, 340, 340, 339, 357, 358, 357, 339, 339, 334, 358, 359, 358, 334, 334, 338, 359, 360, 359, 338, 338, 330, 360, 361, 360, 330, 330, 333, 361, 347, 361, 333, 333, 332, 347, 348, 349, 360, 349, 353, 358, 350, 351, 352, 350, 352, 353, 353, 349, 350, 353, 354, 355, 358, 353, 355, 358, 355, 356, 358, 356, 357, 358, 359, 360, 358, 360, 349, 360, 361, 347, 360, 347, 346, 360, 346, 348, 362, 363, 364, 362, 364, 365, 362, 366, 367, 362, 368, 369, 362, 369, 363, 366, 362, 370, 366, 371, 372, 366, 372, 373, 373, 374, 367, 373, 367, 366, 375, 367, 376, 375, 376, 377, 368, 362, 367, 368, 367, 375, 378, 379, 364, 364, 363, 378, 380, 378, 363, 363, 369, 380, 381, 380, 369, 369, 368, 381, 382, 381, 368, 368, 375, 382, 383, 382, 375, 375, 377, 383, 384, 383, 377, 377, 376, 384, 385, 384, 376, 376, 367, 385, 386, 385, 367, 367, 374, 386, 387, 386, 374, 374, 373, 387, 388, 387, 373, 373, 372, 388, 389, 388, 372, 372, 371, 389, 390, 389, 371, 371, 366, 390, 391, 390, 366, 366, 370, 391, 392, 391, 370, 370, 362, 392, 393, 392, 362, 362, 365, 393, 379, 393, 365, 365, 364, 379, 380, 381, 392, 381, 385, 390, 382, 383, 384, 382, 384, 385, 385, 381, 382, 385, 386, 387, 390, 385, 387, 390, 387, 388, 390, 388, 389, 390, 391, 392, 390, 392, 381, 392, 393, 379, 392, 379, 378, 392, 378, 380, 300, 299, 329, 301, 326, 312, 301, 312, 304, 326, 301, 300, 326, 300, 328, 326, 324, 322, 326, 322, 314, 326, 314, 312, 322, 320, 318, 322, 318, 314, 318, 316, 314, 306, 312, 310, 306, 310, 308, 304, 312, 306, 171, 253, 250, 171, 250, 252, 171, 252, 173, 174, 228, 229, 174, 229, 231, 174, 231, 253, 394, 224, 223, 228, 174, 394, 228, 394, 223, 253, 171, 174, 252, 204, 173, 204, 200, 173, 394, 233, 236, 394, 236, 224, 233, 394, 174, 233, 174, 179];
	var vertices = [23.4396, 19.4658, -16.5797, 23.8352, 18.9897, -16.5797, 23.8352, 19.942, 13.7775, 23.4396, 20.4182, 13.7775, 21.4616, 21.2516, 13.7775, 21.4616, 19.942, -16.5797, 21.066, 21.7278, 12.8434, 20.077, 20.8944, -14.7116, 21.066, 21.7278, 14.7116, 19.6814, 21.7278, 29.6567, 23.4396, 20.4182, 35.2611, 22.4506, 20.8944, 35.2611, 20.077, 20.8944, 35.2611, 23.4396, 16.1325, -45.0688, 19.6814, 16.6087, -47.404, 14.9341, 16.6087, -49.2721, 14.5385, 28.7516, 22.6512, 15.9231, 28.2754, 20.316, 14.5385, 28.2754, 23.5852, 19.6814, 20.4182, 48.8051, 21.066, 18.9897, 49.2721, 20.077, 19.4658, 51.1403, 11.7693, 20.8944, 50.2062, -0.890116, 20.8944, 41.3326, -0.890117, 20.8944, 51.6073, -13.5495, 20.8944, 50.2062, -21.4616, 20.4182, 48.3381, -21.4616, 21.7278, 34.7941, 25.2199, 3.98961, -17.5138, 25.2199, 4.4658, -19.849, 23.8352, 3.51341, -19.849, 25.2199, 12.442, -17.9808, 25.2199, 14.3468, -23.5852, 25.2199, 11.9658, -22.1841, 23.4396, 12.9182, -47.871, 24.8243, 11.9658, -39.4644, 24.8243, 14.823, -37.1292, 24.8243, 15.1801, -33.393, 23.4396, 3.9896, -52.0743, 23.8352, 4.4658, -40.8655, 25.2199, 15.1801, -28.2556, 24.8243, 12.9182, 13.7775, 24.8243, 4.4658, 14.2445, 23.8352, 3.51341, 14.2445, 23.8352, 3.51341, -17.5138, 17.3077, 3.51341, -19.849, 17.3077, 4.4658, -19.849, 17.3077, 14.823, -24.9863, 17.3077, 11.9658, -22.1841, 25.2199, 8.75153, 24.5193, 24.8243, 4.4658, 22.6512, 25.2199, 12.9182, 27.3215, 24.8243, 13.3944, 29.6567, 24.8243, 13.3944, 34.7941, 25.2199, 11.0134, 24.5193, 23.8352, 3.51342, 21.7171, 16.9121, 8.75153, 24.5193, 16.9121, 4.4658, 22.6512, 16.9121, 11.0134, 24.5193, 16.9121, 13.3944, 34.7941, 16.9121, 13.3944, 29.6567, 16.9121, 12.9182, 25.9204, 23.4396, 4.4658, 51.1403, 23.8352, 4.94199, 41.3326, 23.4396, 3.98961, 43.6677, 23.4396, 12.9182, 50.2062, 23.8352, 8.75153, 40.8655, 24.8243, 11.9658, 39.4644, 24.8243, 12.9182, 37.5963, 23.4396, 4.94199, 52.5414, 23.4396, 12.9182, 52.0743, 11.7693, 4.4658, 56.2776, 23.4396, 3.98961, 51.1403, 16.9121, 3.98961, 42.2666, 16.9121, 4.94199, 41.3326, 16.9121, 8.75153, 40.8655, 16.9121, 11.9658, 39.4644, 16.9121, 12.9182, 37.5963, 23.4396, 12.9182, 51.1403, 17.3077, 15.1801, -33.393, 17.3077, 14.823, -37.1292, 21.4616, 12.442, -50.6732, 22.4506, 4.4658, -53.0084, 21.066, 12.9182, -49.2721, 12.1649, 12.9182, -54.8765, 12.1649, 12.442, -57.2117, 17.3077, 15.1801, -28.2556, 15.9231, 27.323, -2.10166, 20.077, 21.2516, 12.8434, 15.9231, 27.7992, 12.8434, 19.6814, 20.4182, -16.5797, 15.9231, 28.2754, -3.03573, 14.5385, 28.7516, 0.70055, 15.9231, 28.7516, 13.7775, 14.5385, 30.1802, 13.7775, 15.9231, 28.2754, 12.8434, 19.6814, 21.7278, 27.7886, 15.9231, 27.323, 20.316, 20.077, 21.7278, 14.7116, 15.9231, 27.7992, 14.7116, 15.9231, 28.2754, 14.7116, 11.7693, 20.4182, 53.4754, 11.7693, 12.9182, 55.3436, 23.4396, 3.51341, -41.3326, 23.4396, 3.51341, -52.0743, 17.3077, 4.4658, -40.8655, 12.1649, 3.51341, -58.6128, 12.1649, 3.9896, -58.6128, 22.4506, 3.9896, -52.0743, 16.9121, 3.51342, 21.7171, 12.1649, 4.4658, -59.5469, 11.7693, 3.98961, 56.2776, 17.3077, 11.9658, -39.4644, 0.0989023, 20.4182, -22.6512, -21.8572, 19.942, -17.0468, -20.077, 16.6087, -47.404, -14.9341, 16.6087, -50.2062, 0.49451, 16.6087, -50.2062, 0.0989023, 20.4182, -22.1841, 14.9341, 27.7992, -3.96979, 19.6814, 20.4182, -16.5797, 13.1539, 29.2278, 20.316, 0.098899, 28.7516, 25.4534, 0.0988991, 29.2278, 23.5852, 0.098899, 28.2754, 25.9204, 12.1649, 4.94199, 57.2117, 12.1649, 12.9182, 57.2117, -0.890118, 3.98961, 57.2117, 16.9121, 13.3944, 24.5193, 16.9121, 13.3944, 39.4644, 0.494511, 3.51341, -59.5469, 17.3077, 15.1801, -22.6512, 17.3077, 3.51341, -41.3326, 17.3077, 15.1801, -38.5303, 0.494511, 3.9896, -59.5469, -17.7034, 3.51342, 20.783, -17.7034, 3.51341, -41.3326, -17.7034, 3.51341, -19.849, -0.890118, 4.4658, 57.2117, -13.5495, 4.4658, 56.2776, -17.7034, 3.98961, 42.2666, -13.5495, 3.98961, 56.2776, -0.890117, 20.4182, 54.4095, 0.49451, 12.9182, -55.8106, 0.0989012, 28.7516, -6.30497, 0.0989013, 28.2754, -9.10717, -13.9451, 30.1802, 20.316, -14.9341, 30.1802, 13.7775, -14.9341, 28.7516, -0.700555, -16.3187, 28.2754, -3.03573, -0.890116, 21.7278, 40.3985, 19.6814, 21.7278, 34.7941, -21.4616, 21.7278, 34.7941, 14.9341, 27.323, -3.96979, 0.0989013, 27.323, -9.10717, -20.4726, 20.4182, -16.5797, -15.3297, 27.323, -3.9698, 0.0989013, 27.7992, -9.57421, -0.890116, 21.7278, 39.4644, -20.077, 21.7278, 33.86, -14.9341, 27.7992, 23.5852, 0.098899, 27.7992, 25.9204, 14.5385, 27.7992, 23.5852, 18.6924, 21.7278, 34.7941, -14.9341, 28.2754, 23.5852, -15.3297, 27.7992, -3.9698, -15.3297, 28.7516, 22.6512, -0.890118, 12.9182, 57.2117, -13.5495, 20.4182, 53.4754, -13.5495, 12.9182, 55.3436, -12.5605, 12.9182, -55.8106, -24.2308, 16.1325, -46.4699, -21.4616, 12.9182, -50.2062, -24.2308, 12.9182, -49.2721, -24.2308, 19.4658, -17.0468, -22.8462, 20.8944, 34.7941, -24.2308, 20.4182, 13.7775, -21.8572, 21.2516, 13.7775, -24.2309, 20.4182, 34.7941, -25.2199, 19.942, 13.7775, -16.3187, 28.2754, 20.316, -21.4616, 19.4658, 50.2062, -22.8462, 18.9897, 49.2721, -16.3187, 28.7516, 13.7775, -21.4616, 20.8944, -14.7116, -17.3077, 27.7992, -3.03573, -17.7034, 28.2754, 12.8434, -17.3077, 28.2754, 14.7116, -17.3077, 27.7992, 14.7116, -21.4616, 21.7278, 12.8434, -17.3077, 27.323, -3.03573, -24.2309, 12.9182, 50.2062, 0.49451, 12.442, -58.1458, 0.494511, 4.4658, -59.5469, -12.5605, 3.9896, -58.6128, -12.5605, 12.442, -57.2117, -12.5605, 4.4658, -59.5469, -12.5605, 3.51341, -58.6128, -21.4616, 12.442, -50.6732, -21.8572, 4.4658, -53.4754, -24.2308, 3.9896, -52.0743, -21.4616, 3.9896, -52.0743, -22.8462, 3.51341, -52.0743, -24.2308, 3.51341, -41.3326, -24.2308, 4.4658, -40.8655, -0.890118, 4.94199, 58.1458, -0.890118, 12.9182, 59.5469, -13.9451, 12.9182, 57.2117, -13.9451, 4.94199, 57.2117, -25.2199, 12.9182, 51.6073, -25.2199, 4.94199, 52.0743, -25.2199, 12.9182, 49.7392, -25.2199, 4.94199, 50.2062, -25.2199, 4.94199, 41.3326, -25.2199, 8.75153, 40.3985, -25.2199, 11.9658, 38.9974, -25.2199, 13.3944, 37.5963, -25.2199, 13.8706, 34.7941, -24.2309, 3.98961, 50.2062, -25.2199, 3.98961, 42.2666, -21.4616, 21.7278, 14.7116, -21.4616, 21.7278, 28.7226, -25.2199, 3.51341, -19.849, -25.2199, 4.4658, -19.849, -25.2199, 3.98961, -17.5138, -25.2199, 3.51341, -17.5138, -25.2199, 3.51341, 14.2445, -17.7034, 4.4658, -19.849, -25.2199, 11.9658, -22.1841, -25.2199, 14.823, -24.9863, -17.7034, 14.823, -24.9863, -25.2199, 15.1801, -28.2556, -17.7034, 11.9658, -22.1841, -25.2199, 12.9182, 13.7775, -25.2199, 11.0134, 23.5852, -25.2199, 8.75153, 23.5852, -25.2199, 4.4658, 14.2445, -25.2199, 13.3944, 28.7226, -25.2199, 12.9182, 25.9204, -25.2199, 4.94199, 22.6512, -25.2199, 3.51342, 20.783, -17.7034, 4.4658, 22.6512, -17.7034, 8.75153, 23.5852, -17.7034, 13.3944, 28.7226, -17.7034, 12.9182, 25.9204, -17.7034, 11.0134, 23.5852, -17.7034, 4.94199, 41.3326, -17.7034, 13.3944, 37.5963, -17.7034, 11.9658, 38.9974, -17.7034, 8.75153, 40.3985, -25.2199, 14.823, -37.5963, -17.7034, 14.823, -37.5963, -25.2199, 11.9658, -39.9314, -25.2199, 15.1801, -34.327, -17.7034, 15.1801, -34.327, -17.7034, 15.1801, -28.2556, -17.7034, 13.8706, 34.7941, -17.3077, 27.7992, 12.8434, -16.3187, 27.7992, 20.316, -21.4616, 21.7278, 14.7116, -21.4616, 21.7278, 27.7885, -17.7034, 4.4658, -40.8655, -17.7034, 11.9658, -39.9314, -17.7034, 13.3944, 24.5193, -17.7034, 15.1801, -23.5852, -17.7034, 13.8706, 38.9974, -17.7034, 15.1801, -39.4644, 17.3077, 16.1325, -30.5908, 17.3077, 11.0134, -22.6512, 17.3077, 0.77531, -33.393, 17.3077, 2.68008, -36.1952, 17.3077, 14.3468, -36.1952, 17.3077, 15.6563, -33.393, 17.3077, 15.6563, -27.7886, 17.3077, 14.3468, -24.9863, 17.3077, 8.27533, -22.6512, 17.3077, 4.94199, -22.6512, 17.3077, 2.68008, -24.9863, 17.3077, 0.77531, -27.7886, 17.3077, 0.299117, -30.5908, 17.3077, 11.0134, -38.5303, 17.3077, 4.94199, -38.5303, 17.3077, 8.27533, -38.5303, 23.4396, 16.1325, -30.5908, 23.4396, 15.6563, -27.7885, 23.4396, 15.6563, -33.393, 23.4396, 14.3468, -36.1952, 23.4396, 11.0134, -38.5303, 23.4396, 8.27533, -38.5303, 23.4396, 4.94199, -38.5303, 23.4396, 2.68008, -36.1952, 23.4396, 0.77531, -33.393, 23.4396, 0.299117, -30.5908, 23.4396, 0.77531, -27.7885, 23.4396, 2.68008, -24.9863, 23.4396, 4.94199, -22.6512, 23.4396, 8.27533, -22.6512, 23.4396, 11.0134, -22.6512, 23.4396, 14.3468, -24.9863, -19.088, 16.1325, -30.5908, -25.2199, 15.6563, -27.7886, -25.2199, 15.6563, -33.393, -19.088, 15.6563, -33.393, -19.088, 14.3468, -36.1952, -25.2199, 14.3468, -36.1952, -19.088, 11.0134, -38.5303, -25.2199, 11.0134, -38.5303, -19.088, 8.27533, -38.5303, -25.2199, 8.27533, -38.5303, -19.088, 4.94199, -38.5303, -25.2199, 4.94199, -38.5303, -19.088, 2.68008, -36.1952, -25.2199, 2.68008, -36.1952, -19.088, 0.77531, -33.393, -25.2199, 0.77531, -33.393, -19.088, 0.299117, -30.5908, -25.2199, 0.299117, -30.5908, -19.088, 0.77531, -27.7886, -25.2199, 0.77531, -27.7886, -19.088, 2.68008, -24.9863, -25.2199, 2.68008, -24.9863, -19.088, 4.94199, -22.6512, -25.2199, 4.94199, -22.6512, -19.088, 8.27533, -22.6512, -25.2199, 8.27533, -22.6512, -19.088, 11.0134, -22.6512, -25.2199, 11.0134, -22.6512, -19.088, 14.3468, -24.9863, -25.2199, 14.3468, -24.9863, -19.088, 15.6563, -27.7886, 17.3077, 9.58486, 38.5303, 17.3077, 14.823, 31.5248, 17.3077, 14.3468, 35.2611, 17.3077, 12.9182, 37.5963, 17.3077, 3.98961, 38.5303, 17.3077, 1.72769, 26.8545, 17.3077, 12.9182, 26.8545, 17.3077, 14.3468, 28.7226, 17.3077, 7.32295, 39.4644, 17.3077, 1.7277, 37.5963, 17.3077, 0.29912, 35.2611, 17.3077, -0.177073, 31.5248, 17.3077, 0.29912, 28.7226, 17.3077, 9.58486, 24.9863, 17.3077, 3.98961, 24.9863, 17.3077, 7.32295, 24.5193, 22.4506, 14.823, 31.5248, 22.4506, 14.3468, 35.2611, 22.4506, 14.3468, 28.7226, 22.4506, 12.9182, 26.8545, 22.4506, 9.58486, 24.9863, 22.4506, 7.32295, 24.5193, 22.4506, 3.98961, 24.9863, 22.4506, 1.72769, 26.8545, 22.4506, 0.29912, 28.7226, 22.4506, -0.177073, 31.5248, 22.4506, 0.29912, 35.2611, 22.4506, 1.7277, 37.5963, 22.4506, 3.98961, 38.5303, 22.4506, 7.32295, 39.4644, 22.4506, 9.58486, 38.5303, 22.4506, 12.9182, 37.5963, -25.2199, 9.58486, 38.5303, -25.2199, 14.823, 31.5248, -25.2199, 14.3468, 35.2611, -25.2199, 12.9182, 37.5963, -25.2199, 3.98961, 38.5303, -25.2199, 1.72769, 26.8545, -25.2199, 12.9182, 26.8545, -25.2199, 14.3468, 28.7226, -25.2199, 7.32295, 39.4644, -25.2199, 1.7277, 37.5963, -25.2199, 0.29912, 35.2611, -25.2199, -0.177073, 31.5248, -25.2199, 0.29912, 28.7226, -25.2199, 9.58486, 24.9863, -25.2199, 3.98961, 24.9863, -25.2199, 7.32295, 24.5193, -19.088, 14.823, 31.5248, -19.088, 14.3468, 35.2611, -19.088, 14.3468, 28.7226, -19.088, 12.9182, 26.8545, -19.088, 9.58486, 24.9863, -19.088, 7.32295, 24.5193, -19.088, 3.98961, 24.9863, -19.088, 1.72769, 26.8545, -19.088, 0.29912, 28.7226, -19.088, -0.177073, 31.5248, -19.088, 0.29912, 35.2611, -19.088, 1.7277, 37.5963, -19.088, 3.98961, 38.5303, -19.088, 7.32295, 39.4644, -19.088, 9.58486, 38.5303, -19.088, 12.9182, 37.5963, -25.2199, 12.442, -17.0468];
	
	var nTris = coordinates.length / 3;
	var tris = new Array();
	for(var i = 0; i < nTris; i++)
	{
		var a = new Array();
		a[0] = coordinates[i * 3];
		a[1] = coordinates[i * 3 + 1];
		a[2] = coordinates[i * 3 + 2];
	
		tris.push(a);		
	}
	
	var nVerts = vertices.length / 3;
	var verts = new Array();
	for(var j = 0; j < nVerts; j++)
	{
		var b = new Array();
		b[0] = vertices[j * 3];
		b[1] = vertices[j * 3 + 1];
		b[2] = vertices[j * 3 + 2];

		verts.push(b);
	}
	
	var triCount = tris.length;
	for(var k = 0; k < 	triCount; k++)
	{
		var t = tris[k];
		var v1 = verts[t[0]];
		var v2 = verts[t[1]];
		var v3 = verts[t[2]];
		
		DrawTri(v1[0], v1[1], v1[2] + 100, v2[0], v2[1], v2[2] + 100, v3[0], v3[1], v3[2] + 100);
		
		/*
		DrawTri( 	verts[tris[k][0]][0], verts[tris[k][0]][1], verts[tris[k][0]][2],
					verts[tris[k][1]][0], verts[tris[k][1]][1], verts[tris[k][1]][2], 
					verts[tris[k][2]][0], verts[tris[k][2]][1], verts[tris[k][2]][2]);	
			*/		
		//ctx.fillStyle = 'rgba(100,50,50,0.4)';
	}		

}

var t = 0;

// Dibuja un Bosque
function draw() 
{
	if (canvas.getContext)
	{
		ctx.fillStyle = 'rgba(255,255,255,1)';
		ctx.fillRect(0,0,1000,800);

		t+= 0.1;
		
		// Bounding Box de la palmera
		var min_x = -25.2199;
		var min_y = -0.177073;
		var min_z = -59.5469;
		var max_x = 25.2199;
		var max_y = 30.1802;
		var max_z = 59.5469;
		
		
		
		var LAx = 0 - 1;
		var LAy = 15.0015635 - 1;
		var LAz = 0;
		var LFx = -0.051326599721381795;
		var LFy = 15.0015635;
		var LFz = -1.9993412865644127;
		
		
		/*
		// Quiero mirar el centro de la palmera
		// LA = Look At = Objetivo = a donde apunta la camara
		var LAx = (min_x + max_x) / 2;
		var LAy = (min_y + max_y) / 2;
		var LAz = (min_z + max_z) / 2;
		
		// Calculo el punto de vista = la posicion del observador (camara u ojo) 
		// girando alrededor del centro de la palmera
		var LFx = LAx + Math.sin(t) * 2;
		var LFy = LAy ;
		var LFz = LAz + Math.cos(t) * 2;
*/
	
		
		// Calculo la transformacion para pasar todo al espacio del camara
		// La Z es la direccion hacia la camara,
		// La Y es la direccion hacia arriba
		// La X es la direccion hacia la derecha.

		// Eje z = normalizado( LA - LF)
		var Zx = LAx - LFx;
		var Zy = LAy - LFy;
		var Zz = LAz - LFz;
		var len = Math.sqrt(Zx*Zx + Zy*Zy + Zz*Zz);
		Zx /= len;
		Zy /= len;
		Zz /= len;

		// Eje x = normalizado ( cross ( Up = (0,1,0) , Eje z))
		var Xx = Zz;
		var Xy = 0;
		var Xz = -Zx;
		len = Math.sqrt(Xx*Xx + Xy*Xy + Xz*Xz);
		Xx /= len;
		Xy /= len;
		Xz /= len;

		// cross ( Eje z , Eje x)
		var Yx = Zy*Xz-Zz*Xy;
		var Yy = Zz*Xx-Zx*Xz;
		var Yz = Zx*Xy-Zy*Xx;

		// Ya tengo las 3 direcciones, son una Base Ortonormal de R3 
		// la matriz creada asi es la matriz de cambio de bases. 

		
		// Armo la matriz de View: Parte de Rotacion
		m11 = Xx;		m12 = Yx;		m13 = Zx;	
		m21 = Xy;		m22 = Yy;		m23 = Zy;
		m31 = Xz;		m32 = Yz;		m33 = Zz;

		// Parte de Translacion
		// -dot (x , LA)
		tras_x = - (Xx*LAx + Xy*LAy + Xz*LAz);
		// -dot (y , LA)
		tras_y = - (Yx*LAx + Yy*LAy + Yz*LAz);
		// -dot (z , LA)
		tras_z = - (Zx*LAx + Zy*LAy + Zz*LAz);

		palmera();
	}
}

function animate()
{   
	canvas = document.getElementById('mycanvas');
	ctx = canvas.getContext('2d');
	setInterval(draw, 100);
} 




</script>
</head>
<body onload="animate();">
	<canvas id="mycanvas" width="1000" height="700"></canvas>

</body>
</html>
 
